from datetime import datetime
from enum import unique

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

"""NodeData"""
class NodeData(db.Model):
    __tablename__ = 'node_data'
    id = db.Column(db.Integer, primary_key=True)
    key = db.Column(db.Integer,nullable=False)
    category = db.Column(db.String(255), nullable=False)
    text = db.Column(db.String(255), nullable=False)
    loc = db.Column(db.String(255), nullable=False)
    project_id = db.Column(db.Integer, nullable=False)

    def to_dict(self):
        return {
            'key': self.key,
            'category': self.category,
            'text': self.text,
            'loc':self.loc
        }

    def __repr__(self):
        return f'<NodeData {self.name}>'

"""LinkData"""
class LinkData(db.Model):
    __tablename__ = 'link_data'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    from_ = db.Column(db.String(255), nullable=False)
    to = db.Column(db.String(255), nullable=False)
    text = db.Column(db.String(255), nullable=False)
    project_id = db.Column(db.Integer, nullable=False)

    def to_dict(self):
        return {
            'from': self.from_,
            'to': self.to,
            'text':self.text
        }

    def __repr__(self):
        return f'<LinkData {self.name}>'


"""Project"""
class Project(db.Model):
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    description = db.Column(db.String(255), nullable=False)
    create_time = db.Column(db.DateTime,default=datetime.utcnow)

    def __repr__(self):
        return f'<Project {self.name}>'
